package com.zhihaoliang.room.util

import android.util.Log
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory


/**
 * @author 支豪亮
 * @date 2023/1/20 09:33
 * @des Log 信息的打印
 */

fun log(msg: Any?) {
    if (msg == null) {
        Log.e("room", "null")
        return
    }
    Log.e("room", msg.toString())
}

fun <T> logJson(obj: T) {
    if(obj == null){
        Log.e("room", "null")
        return
    }
    val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
    val adapter = moshi.adapter(obj!!::class.java as Class<T>?).indent("   ")
    val result = adapter.toJson(obj)
    log(result)
}